const {ccclass, property} = cc._decorator;

@ccclass
export default class EnemyControl extends cc.Component {

    @property
    private speed: number = 300;

    @property
    public isDestory: boolean = false;

    start() {

    }

    update(dt) {
        // 移动
        if (!this.isDestory) {
            this.node.y -= this.speed * dt;
        }
        // 离开屏幕销毁子弹
        if (this.node.getPosition().y < 0) {
            this.node.destroy();
        }
    }

    // 死亡销毁
    die(): void {
        if (!this.isDestory) {
            this.isDestory = true;
            cc.loader.loadRes('enemy0_die', cc.SpriteFrame, (err, res) => {
                this.node.getComponent(cc.Sprite).spriteFrame = res;
            })
            // 300毫秒后销毁
            setTimeout(() => {
                this.node.destroy();
            }, 300);
        }
    }

}
